import { UserStatus, UserHobby } from '@/enum';
import { IsEnum, IsOptional, Validate } from 'class-validator';

export default class UserListDto {
  pageNum: number;
  pageSize: number;
  username: string;

  @IsOptional()
  @Validate((value: string) => {
    const values = value.split('|').map((item) => Number(item.trim()));

    const isValid = values.every((item) =>
      Object.values(UserHobby).includes(item),
    );
    if (!isValid) {
      throw new Error('偏好必须是 0:休闲 1:人文 2:现代 3:自然, 用 | 分割');
    }
  })
  hobby: string;

  @IsOptional()
  @IsEnum(UserStatus, {
    message: '状态必须是 0:正常 1:禁言',
  })
  status: number;
}
